﻿namespace CSharpPro._0929;

public class Demo 
{ 
    //作业1:输出1000以内的水仙花数
    public void TestPrint()
    {        
        Console.WriteLine("1000以内的水仙花数有：");        
        for (int i = 100; i < 1000; i++)
        {            
            int hundreds = i / 100;            
            int tens = (i / 10) % 10;            
            int units = i % 10;                        
            int sum = (int)(Math.Pow(hundreds, 3) + Math.Pow(tens, 3) + Math.Pow(units, 3));                        
            
            if (sum == i)
            {                
                Console.Write(i + " ");
            }
        }        
        Console.WriteLine("\n");
    }   
    
    // 作业2：输出100以内的所有质数    
    public void PrintPrimeNumbers()
    {        
        Console.WriteLine("100以内的所有质数有：");        
        List<int> primes = new List<int>();                
        
        for (int i = 2; i <= 100; i++)
        {            
            bool isPrime = true;                        
            
            for (int j = 2; j <= Math.Sqrt(i); j++)
            {                
                if (i % j == 0)
                {                    
                    isPrime = false;                    
                    break;
                }
            }                        
            if (isPrime)
            {                
                primes.Add(i);
            }
        }                
        
        foreach (int prime in primes)
        {            
            Console.Write(prime + " ");
        }        
        Console.WriteLine();
    }
    
        //int num = 10;
        //Console.WriteLine(num / 0);

        /*
         do
        {
            Console.Write(num+" ");
            num--;
        }while(num > 15);
        
         while (num > 5)
        {
           Console.Write(num+"\t");
           num--;
        }
        */
}